home *** CD-ROM | disk | FTP | other *** search
/ Giga Games 1 / Giga Games.iso / net / usenet / volume3 / conquer / part03 < prev    next >
Encoding:
Internet Message Format  |  1988-01-23  |  54.2 KB

  1. Path: uunet!seismo!sundc!pitstop!sun!amdcad!ames!ll-xn!mit-eddie!uw-beaver!tektronix!tekgen!tekred!games-request
  2. From: games-request@tekred.TEK.COM
  3. Newsgroups: comp.sources.games
  4. Subject: v03i072:  conquer - version 2 of the renamed conquest adventure game, Part03/06
  5. Message-ID: <2106@tekred.TEK.COM>
  6. Date: 22 Jan 88 21:33:59 GMT
  7. Sender: billr@tekred.TEK.COM
  8. Lines: 2168
  9. Approved: billr@tekred.TEK.COM
  10.  
  11. Submitted by: ihnp4!mhuxd!smile (Ed Barlow)
  12. Comp.sources.games: Volume 3, Issue 72
  13. Archive-name: conquer/Part03
  14.  
  15. #! /bin/sh
  16.  
  17. # This is a shell archive.  Remove anything before this line, then unpack
  18. # it by saving it into a file and typing "sh file".  To overwrite existing
  19. # files, type "sh file -c".  You can also feed this as standard input via
  20. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  21. # will see the following message at the end:
  22. #        "End of archive 3 (of 6)."
  23. # Contents:  commands.c magic.c main.c run
  24. # Wrapped by billr@tekred on Fri Jan 22 13:27:06 1988
  25. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  26. if test -f commands.c -a "${1}" != "-c" ; then 
  27.   echo shar: Will not over-write existing file \"commands.c\"
  28. else
  29. echo shar: Extracting \"commands.c\" \(18869 characters\)
  30. sed "s/^X//" >commands.c <<'END_OF_commands.c'
  31. X/*conquer is copyrighted 1986 by Ed Barlow.
  32. X *  I spent a long time writing this code & I hope that you respect this.  
  33. X *  I give permission to alter the code, but not to copy or redistribute
  34. X *  it without my explicit permission.  If you alter the code, 
  35. X *  please document changes and send me a copy, so all can have it.  
  36. X *  This code, to the best of my knowledge works well,  but it is my first
  37. X *  'C' program and should be treated as such.  I disclaim any
  38. X *  responsibility for the codes actions (use at your own risk).  I guess
  39. X *  I am saying "Happy gaming", and am trying not to get sued in the process.
  40. X *                                                Ed
  41. X */
  42. X
  43. X/*    commands.c        */
  44. X
  45. X/*include files*/
  46. X#include "header.h"
  47. X#include "data.h"
  48. X#include <ctype.h>
  49. X
  50. Xextern short xcurs,ycurs,xoffset,yoffset;
  51. Xextern FILE *fexe;        /*execute file pointer*/
  52. Xextern short country;
  53. Xextern short selector;
  54. Xextern short pager;
  55. Xextern short xcurs,ycurs,xoffset,yoffset;
  56. X
  57. X/*change current hex designation*/
  58. Xredesignate()
  59. X{
  60. X    char newdes;
  61. X    short x,y;
  62. X
  63. X    if(country==0){
  64. X        mvaddstr(LINES-1,0,"SUPER USER: CHANGE (v)egitation, (e)levation, (d)esig, (o)wner");
  65. X        refresh();
  66. X        switch(getch()){
  67. X        case 'e':
  68. X            /*simple contour map definitions*/
  69. X            mvprintw(LINES-2,7,"ELEVATIONS: change to %c, %c, %c, %c or %c?",WATER,PEAK,MOUNTAIN,HILL,CLEAR);
  70. X            refresh();
  71. X            newdes=getch();
  72. X            if(newdes!=WATER&&newdes!=PEAK&&newdes!=MOUNTAIN
  73. X            &&newdes!=HILL&&newdes!=CLEAR) return;
  74. X            sct[XREAL][YREAL].altitude=newdes;
  75. X            if((newdes==PEAK)||(newdes==WATER)) {
  76. X                sct[XREAL][YREAL].owner=0;
  77. X                sct[XREAL][YREAL].people=0;
  78. X                sct[XREAL][YREAL].fortress=0;
  79. X            }
  80. X            /*will fall through as must change vegetation*/
  81. X        case 'v':
  82. X            /*vegetation types*/
  83. X            mvprintw(LINES-2,7,"VEGITATIONS: change to %c, %c, %c, %c, %c, %c, %c, %c, %c, %c, %c or %c?",
  84. X            VOLCANO,DESERT,WASTE,BARREN,LT_VEG,
  85. X            GOOD,WOOD,FORREST,JUNGLE,SWAMP,ICE,NONE);
  86. X            refresh();
  87. X            newdes=getch();
  88. X            if(newdes!=VOLCANO
  89. X            &&newdes!=DESERT&&newdes!=WASTE
  90. X            &&newdes!=BARREN&&newdes!=LT_VEG
  91. X            &&newdes!=NONE&&newdes!=GOOD
  92. X            &&newdes!=WOOD&&newdes!=FORREST&&newdes!=JUNGLE
  93. X            &&newdes!=SWAMP&&newdes!=ICE) return;
  94. X            sct[XREAL][YREAL].vegetation=newdes;
  95. X            if(isdigit(sct[XREAL][YREAL].vegetation)==0) 
  96. X                sct[XREAL][YREAL].designation=newdes;
  97. X            return;
  98. X        case 'o':
  99. X            mvprintw(LINES-2,7,"what nation owner:");
  100. X            refresh();
  101. X            x = get_number();
  102. X            sct[XREAL][YREAL].owner=x;
  103. X            return;
  104. X        }
  105. X    }
  106. X    if((country!=0)&&(sct[XREAL][YREAL].owner!=country)) {
  107. X        mvprintw(LINES-1,0,"You do not own: hit any key");
  108. X        refresh();
  109. X        getch();
  110. X        return;
  111. X    }
  112. X    mvprintw(LINES-1,0,"hit space to not redesignate anything");
  113. X    clrtoeol();
  114. X    mvprintw(LINES-2,7,"$%d: redesignate to %c, %c, %c, %c or %c?",DESCOST,DMINE,DGOLDMINE,DFARM,DCITY,DCAPITOL);
  115. X    clrtoeol();
  116. X    refresh();
  117. X    /*read answer*/
  118. X    newdes=getch();
  119. X
  120. X    if(newdes!=DMINE&&newdes!=DGOLDMINE&&newdes!=DFARM&&newdes!=DCITY&&newdes!=DCAPITOL) return;
  121. X
  122. X    if((SOWN==country)||(country==0)) {
  123. X        if((isdigit(sct[XREAL][YREAL].vegetation)!=0)||(country==0)) {
  124. X            if(((newdes!=DCITY)&&(newdes!=DCAPITOL))||(country==0)) {
  125. X                /*decrement treasury*/
  126. X                sct[XREAL][YREAL].designation=newdes;
  127. X                if(country==0) {
  128. X                    country=sct[XREAL][YREAL].owner;
  129. X                    SADJDES;
  130. X                    country=0;
  131. X                }
  132. X                else {
  133. X                    SADJDES;
  134. X                    ntn[country].tgold-=DESCOST;
  135. X                }
  136. X            }
  137. X            else if((newdes==DCAPITOL)
  138. X            &&(sct[XREAL][YREAL].designation==DCITY)){
  139. X
  140. X                ntn[country].tgold-=5*DESCOST;
  141. X                ntn[country].tiron-=DESCOST;
  142. X                x=ntn[country].capx;
  143. X                y=ntn[country].capy;
  144. X                sct[x][y].designation=DCITY;
  145. X                if(country==0) {
  146. X                    country=sct[x][y].owner;
  147. X                    SADJDES2;
  148. X                    country=0;
  149. X                }
  150. X                else SADJDES2;
  151. X                sct[XREAL][YREAL].designation=newdes;
  152. X                ntn[country].capx=XREAL;
  153. X                ntn[country].capy=YREAL;
  154. X                if(country==0) {
  155. X                    country=sct[XREAL][YREAL].owner;
  156. X                    SADJDES;
  157. X                    country=0;
  158. X                }
  159. X                else SADJDES;
  160. X            }
  161. X            else if((newdes==DCAPITOL)
  162. X            &&(sct[XREAL][YREAL].designation!=DCITY)){
  163. X                mvprintw(LINES-1,0,"Sector must be a city: hit any key  ");
  164. X                refresh();
  165. X                getch();
  166. X            }
  167. X            else if((ntn[country].tiron>DESCOST)
  168. X            &&(newdes==DCITY)){
  169. X                if(sct[XREAL][YREAL].people>=500){
  170. X                    ntn[country].tgold-=5*DESCOST;
  171. X                    ntn[country].tiron-=DESCOST;
  172. X                    sct[XREAL][YREAL].designation=newdes;
  173. X                    if(country==0) {
  174. X                        country=sct[XREAL][YREAL].owner;
  175. X                        SADJDES;
  176. X                        country=0;
  177. X                    }
  178. X                    else SADJDES;
  179. X                }
  180. X                else {
  181. X                mvprintw(LINES-1,0,"Need 500 people to build to city");
  182. X                refresh();
  183. X                getch();
  184. X                }
  185. X            }
  186. X            else {
  187. X            mvprintw(LINES-1,0,"Not enough iron: hit any key  ");
  188. X            refresh();
  189. X            getch();
  190. X            }
  191. X        }
  192. X        else {
  193. X        mvprintw(LINES-1,0,"vegetation unlivable: hit any key  ");
  194. X        refresh();
  195. X        getch();
  196. X        }
  197. X    }
  198. X    else {
  199. X    mvprintw(LINES-1,0,"Sorry, you don't own sector: hit any key ");
  200. X    refresh();
  201. X    getch();
  202. X    }
  203. X}
  204. X
  205. X/*build fort or ship-type */
  206. Xconstruct()
  207. X{
  208. X    int nearsea;
  209. X    long cost;
  210. X    int armbonus;
  211. X    int x,y;
  212. X    short nvynum=0;
  213. X    short mnumber,wnumber;
  214. X    short isgod=0;
  215. X    char type;
  216. X
  217. X    if(country==0){
  218. X        isgod=1;
  219. X        country=sct[XREAL][YREAL].owner;
  220. X    }
  221. X
  222. X    if(sct[XREAL][YREAL].owner!=country) {
  223. X        mvaddstr(LINES-1,0,"You do not own: hit any key");
  224. X        refresh();
  225. X        getch();
  226. X        if(isgod==1) country=0;
  227. X        return;
  228. X    }
  229. X
  230. X    if((isgod == 0) && (ntn[country].tgold < 0 )) {
  231. X        mvaddstr(LINES-1,0,"You are broke: hit any key");
  232. X        refresh();
  233. X        getch();
  234. X        return;
  235. X    }
  236. X
  237. X    if((sct[XREAL][YREAL].designation==DCITY)
  238. X    ||(sct[XREAL][YREAL].designation==DCAPITOL)) {
  239. X        /*calculate cost for fort*/
  240. X        cost=FORTCOST;
  241. X        if(isgod==1) cost=0;
  242. X        else for(x=1;x<=sct[XREAL][YREAL].fortress;x++) 
  243. X            cost*=2;
  244. X
  245. X        if(sct[XREAL][YREAL].designation==DCITY) armbonus=8;
  246. X        else if(sct[XREAL][YREAL].designation==DCAPITOL) armbonus=10;
  247. X        if(magic(country,ARCHITECT)==1) armbonus*=2;
  248. X
  249. X        move(LINES-1,0);
  250. X        clrtoeol();
  251. X        mvprintw(LINES-2,0,"Construct <f>ortifications (+%d%% - %ld gold) or <s>hips?:",armbonus,cost);
  252. X        clrtoeol();
  253. X        refresh();
  254. X        type=getch();
  255. X    }
  256. X    else {
  257. X        mvprintw(LINES-2,0,"Must construct in city or capitol--hit any key");
  258. X        clrtoeol();
  259. X        refresh();
  260. X        getch();
  261. X        return;
  262. X    }
  263. X
  264. X    /* construct ships*/
  265. X    if (type=='s') {
  266. X        /*check if next to sea*/
  267. X        nearsea=0;
  268. X        for(x=XREAL-1;x<=XREAL+1;x++)
  269. X            for(y=YREAL-1;y<=YREAL+1;y++)
  270. X                if(sct[x][y].altitude==WATER) nearsea=1;
  271. X
  272. X        if (nearsea==0) {
  273. X            mvprintw(LINES-2,0,"not in a harbor: hit space");
  274. X            clrtoeol();
  275. X            refresh();
  276. X            getch();
  277. X            if(isgod==1) country=0;
  278. X            return;
  279. X        }
  280. X
  281. X        mvprintw(LINES-2,0,"build how many merchant ships:");
  282. X        clrtoeol();
  283. X        refresh();
  284. X        mnumber = get_number();
  285. X        mvprintw(LINES-2,0,"build how many warships:");
  286. X        clrtoeol();
  287. X        refresh();
  288. X        wnumber = get_number();
  289. X        /*sanity checks*/
  290. X        if((wnumber>100)||(wnumber<0)) wnumber=0;
  291. X        if((mnumber>100)||(mnumber<0)) mnumber=0;
  292. X        mvprintw(LINES-2,0,"constructing %hd warships and %hd merchant",wnumber,mnumber);
  293. X        clrtoeol();
  294. X
  295. X        if((nvynum=getselunit()-MAXARM)>=0){
  296. X            if(nvynum>=MAXNAVY){
  297. X                mvaddstr(LINES-1,0,"INVALID NAVY--hit any key");
  298. X                clrtoeol();
  299. X                refresh();
  300. X                getch();
  301. X                if(isgod==1) country=0;
  302. X                return;
  303. X            }
  304. X            mvaddstr(LINES-1,0,"Do you wish to raise a new fleet (y or n)");
  305. X            clrtoeol();
  306. X            refresh();
  307. X            if(getch()=='y') nvynum=(-1);
  308. X        }
  309. X
  310. X        if(nvynum<0) {
  311. X            mvprintw(LINES-2,0,"raising a new fleet");
  312. X            clrtoeol();
  313. X            refresh();
  314. X
  315. X            nvynum=0;
  316. X            x=(-1);
  317. X            while((x==(-1))&&(nvynum<MAXNAVY)) {
  318. X                if(NWAR+NMER<=0) {
  319. X                    x=nvynum;
  320. X                    NWAR=0;
  321. X                    NMER=0;
  322. X                    NADJSHP;
  323. X                }
  324. X                nvynum++;
  325. X            }
  326. X            nvynum=x;
  327. X        }
  328. X
  329. X        if(nvynum==(-1)){
  330. X            mvaddstr(LINES-1,0,"NO FREE NAVIES--hit any key");
  331. X            clrtoeol();
  332. X            refresh();
  333. X            getch();
  334. X            if(isgod==1) country=0;
  335. X            return;
  336. X        }
  337. X
  338. X        mvprintw(LINES-3,0,"Raising fleet %d",nvynum);
  339. X        if((nvynum>=0)&&(nvynum<MAXNAVY)) {
  340. X            NXLOC=XREAL;
  341. X            NYLOC=YREAL;
  342. X            NWAR+=wnumber;
  343. X            NMER+=mnumber;
  344. X            if(isgod==0) {
  345. X            ntn[country].tgold -= (long) wnumber*WARSHPCOST;
  346. X            ntn[country].tgold -= (long) mnumber*MERSHPCOST;
  347. X            }
  348. X            NMOVE=0;
  349. X            NADJSHP;
  350. X            NADJLOC;
  351. X            NADJMOV;
  352. X        }
  353. X        else mvprintw(LINES-2,0,"ERROR!!!!!!!!!!!!!");
  354. X
  355. X        refresh();
  356. X        makebottom();
  357. X    }
  358. X    /* construct fortification points*/
  359. X    else if(type=='f'){
  360. X        if(sct[XREAL][YREAL].people>=500) {
  361. X
  362. X            mvprintw(LINES-1,25,"you build %d%% fort points for %ld gold",armbonus,cost);
  363. X            ntn[country].tgold-=cost;
  364. X            sct[XREAL][YREAL].fortress++;
  365. X            INCFORT;
  366. X        }
  367. X        else mvprintw(LINES-1,25,"need 500 people");
  368. X    }
  369. X    else mvprintw(LINES-1,0,"error");
  370. X
  371. X    if(isgod==1) country=0;
  372. X    refresh();
  373. X}
  374. X
  375. X/*DRAFT IF IN A CITY*/
  376. Xdraft()
  377. X{
  378. X    short armynum;
  379. X    int men=0;
  380. X    short army=(-1);
  381. X    short isgod=0;
  382. X    if(country==0) {
  383. X        isgod=1;
  384. X        country=sct[XREAL][YREAL].owner;
  385. X    }
  386. X    else if(sct[XREAL][YREAL].owner!=country) {
  387. X        mvprintw(LINES-1,0,"You do not own: hit any key");
  388. X        refresh();
  389. X        getch();
  390. X        return;
  391. X    }
  392. X
  393. X    if((sct[XREAL][YREAL].designation!=DCITY)
  394. X    &&(sct[XREAL][YREAL].designation!=DCAPITOL)) {
  395. X        mvprintw(LINES-1,0,"must raise in cities: hit any key");
  396. X        refresh();
  397. X        getch();
  398. X        if(isgod==1) country=0;
  399. X        return;
  400. X    }
  401. X
  402. X    if((sct[XREAL][YREAL].designation==DCITY)
  403. X    &&(sct[XREAL][YREAL].people*(2*CITYLIMIT+(ntn[country].tsctrs/2))<ntn[country].tciv)){
  404. X        mvprintw(LINES-1,0,"need %d people in city: hit any key",ntn[country].tciv/(2*CITYLIMIT+(ntn[country].tsctrs/2)));
  405. X        refresh();
  406. X        getch();
  407. X        if(isgod==1) country=0;
  408. X        return;
  409. X    }
  410. X
  411. X    if(ntn[country].tgold <= 0){
  412. X        mvprintw(LINES-1,0,"you dont have any gold: hit any key");
  413. X        refresh();
  414. X        getch();
  415. X        if(isgod==1) country=0;
  416. X        return;
  417. X    }
  418. X
  419. X    /*raise an untrained army */
  420. X    mvprintw(LINES-3,0,"how many men do you wish to raise:");
  421. X    clrtoeol();
  422. X    refresh();
  423. X    men = get_number();
  424. X    if(men<=0) return;
  425. X    if(men > sct[XREAL][YREAL].people/4) {
  426. X        mvprintw(LINES-2,0,"can only raise %d soldiers",sct[XREAL][YREAL].people/4);
  427. X        clrtoeol();
  428. X        refresh();
  429. X        men = sct[XREAL][YREAL].people/4;
  430. X    }
  431. X    if(men >  (int) (ntn[country].tiron/10)) {
  432. X        mvprintw(LINES-2,0,"aborting--only enough iron for %d troops",ntn[country].tiron/10);
  433. X        clrtoeol();
  434. X        refresh();
  435. X        getch();
  436. X        if(isgod==1) country=0;
  437. X        return;
  438. X    }
  439. X    else {
  440. X        move(LINES-2,0);
  441. X        clrtoeol();
  442. X        ntn[country].tiron -= 10*men;
  443. X    }
  444. X
  445. X    /*count is order of that army in sector*/
  446. X    /*armynum is number of that army*/
  447. X    if((armynum=getselunit())>=0){
  448. X        if(armynum>=MAXARM) {
  449. X            army = -1;
  450. X        } else {
  451. X            mvaddstr(LINES-1,0,"Do you wish to raise a new army:");
  452. X            clrtoeol();
  453. X            refresh();
  454. X            if(getch()!='y') army=armynum;
  455. X            else army= -1;
  456. X        }
  457. X    }
  458. X    if(army==(-1)) {
  459. X        mvprintw(LINES-2,0,"raising a new army");
  460. X        clrtoeol();
  461. X        refresh();
  462. X        armynum=0;
  463. X        while((army==(-1))&&(armynum<MAXARM)) {
  464. X            if(ASOLD<=0) {
  465. X                army=armynum;
  466. X                ASOLD=0;
  467. X                ASTAT=DEFEND; /* set new armies to DEFEND */
  468. X                AADJSTAT;
  469. X                AADJMEN;
  470. X            }
  471. X            armynum++;
  472. X        }
  473. X        if(army==(-1)){
  474. X            mvaddstr(LINES-1,0,"NO FREE ARMIES--hit any key");
  475. X            clrtoeol();
  476. X            refresh();
  477. X            getch();
  478. X            if(isgod==1) country=0;
  479. X            return;
  480. X        }
  481. X        armynum=army;
  482. X    }
  483. X
  484. X    AYLOC=YREAL;
  485. X    AXLOC=XREAL;
  486. X    AADJLOC;
  487. X    AMOVE=0;
  488. X    AADJMOV;
  489. X    ASOLD+=men;
  490. X    AADJMEN;
  491. X    sct[XREAL][YREAL].people -= men;
  492. X    SADJCIV;
  493. X    makemap(); /* if display 'y' is set, this will show new army */
  494. X    if(isgod==0)
  495. X        /*magiced get 1/2 enlistment costs*/
  496. X        if((magic(country,WARRIOR)==1)
  497. X        ||(magic(country,WARLORD)==1)
  498. X        ||(magic(country,CAPTAIN)==1))
  499. X            ntn[country].tgold -= (long) men*ENLISTCOST/2;
  500. X        else ntn[country].tgold -= (long) men*ENLISTCOST;
  501. X    else country=0;
  502. X}
  503. X
  504. X/*adjust picked army*/
  505. Xadjarm()
  506. X{
  507. X    short status;
  508. X    short armynum=0;
  509. X    armynum=getselunit();
  510. X    if((armynum<0)||(armynum>=MAXARM)) {
  511. X        beep();
  512. X        mvprintw(LINES-1,0,"Sorry you have an Invalid army number (%d)",armynum);
  513. X        refresh();
  514. X        getch();
  515. X        return;
  516. X    }
  517. X    if(ASTAT==SCOUT) {
  518. X        beep();
  519. X        mvprintw(LINES-1,0,"Sorry can't change scouts");
  520. X        refresh();
  521. X        getch();
  522. X        return;
  523. X    }
  524. X    clear();
  525. X    mvprintw(0,10,"ADJUST ARMY %d OF NATION %s",armynum,ntn[country].name);
  526. X    mvaddstr(2,10,"1.  March ");
  527. X    mvaddstr(3,10,"2.  Scouting--will not engage enemy if possible");
  528. X    mvaddstr(4,10,"3.  Attack anybody (Hostile+) within 2 sectors");
  529. X    mvaddstr(5,10,"4.  Defend ");
  530. X    mvaddstr(6,10,"5.  Garrison--for a city or Capital");
  531. X    mvaddstr(12,10,"Enter your choice (return to continue):");
  532. X    refresh();
  533. X    status = get_number();
  534. X    if((status<1)||(status>5)) return;
  535. X    if((status==SCOUT)&&(ASOLD>25)){
  536. X        clear();
  537. X        mvaddstr(12,(COLS/2)-6,"MUST HAVE < 25 MEN TO SCOUT");
  538. X        mvaddstr(13,(COLS/2)-12,"HIT ANY KEY TO CONTINUE");
  539. X        refresh();
  540. X        getch();
  541. X        return;
  542. X    }
  543. X    ASTAT=status;
  544. X    AADJSTAT;
  545. X}
  546. X
  547. X/*go through msgfile not rewriting to temp messages you discard*/
  548. X/* then move temp to msgfile*/
  549. Xrmessage()
  550. X{
  551. X    FILE *mesgfp;
  552. X    FILE *fptemp;
  553. X    int i;
  554. X    int count;
  555. X    int contd;
  556. X    int done=0;
  557. X    char tempfile[ 30 ];
  558. X    char mesgfile[ 30 ];
  559. X    char line[80];
  560. X    char save[20][80];
  561. X
  562. X    clear();
  563. X    /*open file*/
  564. X    sprintf(tempfile,"%s:temp",msgfile);
  565. X    if( (fptemp = fopen(tempfile,"w")) == NULL ) {
  566. X        mvprintw(0,0,"error on creating %s--hit return", tempfile);
  567. X        refresh();
  568. X        getch();
  569. X        return;
  570. X    }
  571. X
  572. X    sprintf(mesgfile,"%s%d",msgfile,country);
  573. X    if ((mesgfp=fopen(mesgfile,"r"))==NULL) {
  574. X        mvprintw(0,0,"no messages in %s, hit return",mesgfile);
  575. X        refresh();
  576. X        getch();
  577. X        return;
  578. X    }
  579. X
  580. X    /*read in file a line at at time*/
  581. X    if(fgets(line,80,mesgfp)==NULL) done=1;
  582. X    while(done==0) {
  583. X        contd=0;
  584. X        count=3;
  585. X        if(strncmp(line,ntn[country].name,strlen(ntn[country].name))==0) {
  586. X            clear();
  587. X            standout();
  588. X            /*print to end of message*/
  589. X            while(contd==0) {
  590. X                if(count<22) strcpy(save[count-3],line);
  591. X                mvprintw(count,0,"%s",line);
  592. X                standend();
  593. X                for(i=0;i<strlen(ntn[country].name);i++) 
  594. X                    mvaddch(count,i,' ');
  595. X                count++;
  596. X                if(fgets(line,80,mesgfp)==NULL) contd=1;
  597. X                if(strncmp(line,"END",3)==0) contd=1;
  598. X            }
  599. X            standout();
  600. X            mvaddstr(LINES-3,(COLS/2)-22,"HIT RETURN TO SAVE MESSAGE");
  601. X            mvaddstr(LINES-2,(COLS/2)-22,"HIT ANY OTHER KEY TO CONTINUE");
  602. X            standend();
  603. X            refresh();
  604. X            if(getch()=='\n') {
  605. X                for(i=0;i<count-3;i++) fputs(save[i],fptemp);
  606. X                strcpy(line,"END\n");
  607. X                fputs(line,fptemp);
  608. X            }
  609. X        }
  610. X        else fputs(line,fptemp);
  611. X        if(fgets(line,80,mesgfp)==NULL) done=1;
  612. X    }
  613. X    fclose(mesgfp);
  614. X    fclose(fptemp);
  615. X
  616. X    /*IMPLEMENT A MOVE BETWEEN TMP FILE AND REAL FILE HERE*/
  617. X    move_file( tempfile, mesgfile );
  618. X}
  619. X
  620. Xwmessage()
  621. X{
  622. X    FILE *fp, *fopen();
  623. X    int x,y;
  624. X    int done=0;
  625. X    char ch;
  626. X    char name[12];
  627. X    char realname[12];
  628. X    int temp=(-1);
  629. X    int linedone;
  630. X    char line[100];
  631. X    int nationid;
  632. X
  633. X    /*what nation to send to*/
  634. X    clear();
  635. X    mvprintw(0,0,"to send a message to the administrator, send to 'god':");
  636. X    mvprintw(2,0,"What country name do you wish to send to:");
  637. X    refresh();
  638. X    echo();
  639. X    getstr(name);
  640. X    noecho();
  641. X
  642. X    /*is name valid*/
  643. X    for(nationid=0;nationid<MAXNTN;nationid++) if(ntn[nationid].active!=0)
  644. X        if(strcmp(name,ntn[nationid].name)==0) temp=nationid;
  645. X
  646. X    if(strcmp(name,"god")==0) {
  647. X        temp=0;
  648. X        strcpy(realname,"unowned");
  649. X    }
  650. X    else strcpy(realname,name);
  651. X
  652. X    if (temp==(-1)) {
  653. X        mvprintw(2,0,"error--invalid name");
  654. X        refresh();
  655. X        getch();
  656. X        return;
  657. X    }
  658. X
  659. X    sprintf(line,"%s%d",msgfile,temp);
  660. X    if ((fp=fopen(line,"a+"))==NULL) {
  661. X        mvprintw(4,0,"error opening %s",line);
  662. X        refresh();
  663. X        getch();
  664. X        return;
  665. X    }
  666. X
  667. X    move(0,0);
  668. X    clrtoeol();
  669. X    move(2,0);
  670. X    clrtoeol();
  671. X    standout();
  672. X    mvprintw(3,(COLS-25)/2,"message to nation %s",name);
  673. X    mvprintw(LINES-2,(COLS-25)/2,"end with a return on a new line");
  674. X    mvprintw(LINES-1,(COLS-35)/2,"btw... This is my first editor, any comments?");
  675. X    standend();
  676. X
  677. X    fprintf(fp,"%s Message to %s from %s\n",realname,name,ntn[country].name);
  678. X    fprintf(fp,"%s \n",realname);
  679. X    y=6;
  680. X    x=0;
  681. X    refresh();
  682. X    while(done==0) {
  683. X        linedone=0;
  684. X        ch=' ';
  685. X        /*read line*/
  686. X        while(linedone==0){
  687. X            if(ch=='\b'){
  688. X                if(x>0) x--;
  689. X                mvaddch(y,x,' ');
  690. X                move(y,x);
  691. X                line[x]=' ';
  692. X                refresh();
  693. X                ch=getch();
  694. X            }
  695. X            else if(ch=='\n') linedone=1;
  696. X            else{
  697. X                /*concatonate to end*/
  698. X                line[x]=ch;
  699. X                mvaddch(y,x,ch);
  700. X                if(x<99) x++;
  701. X                else linedone=1;
  702. X                refresh();
  703. X                ch=getch();
  704. X            }
  705. X        }
  706. X        line[x]='\0';
  707. X        if(x<=1) done=1;
  708. X        /*write to file*/
  709. X        fprintf(fp,"%s %s\n",realname,line);
  710. X        x=0;
  711. X        y++;
  712. X    }
  713. X    fputs("END\n",fp);
  714. X    mvprintw(20,0,"Done with messaging");
  715. X    fclose(fp);
  716. X}
  717. X
  718. X/*strategic move of civilians...once only*/
  719. Xmoveciv()
  720. X{
  721. X    short people;
  722. X    short i,j;
  723. X
  724. X    mvaddstr(LINES-1,0,"Moving civilians costs 50 per civilian");
  725. X    if(sct[XREAL][YREAL].owner!=country){
  726. X        mvprintw(LINES-2,0,"you do not own:  hit return");
  727. X        clrtoeol();
  728. X        refresh();
  729. X        getch();
  730. X        return;
  731. X    }
  732. X    else if(sct[XREAL][YREAL].people==0){
  733. X        mvaddstr(LINES-2,0,"nobody lives here!!!:  hit return");
  734. X        clrtoeol();
  735. X        refresh();
  736. X        getch();
  737. X        makebottom();
  738. X        return;
  739. X    }
  740. X
  741. X    clear();
  742. X    mvaddstr(0,0,"Moving civilians costs 50 per civilian");
  743. X    mvprintw(1,0,"sector contains %d people",sct[XREAL][YREAL].people);
  744. X    mvaddstr(2,0,"how many people to move?");
  745. X    clrtoeol();
  746. X    refresh();
  747. X    people = get_number();
  748. X    if((people<0)
  749. X    ||(people>sct[XREAL][YREAL].people)
  750. X    ||(people*50>ntn[country].tgold)){
  751. X        mvaddstr(5,0,"Sorry...Input error or you do not have the gold");
  752. X        clrtoeol();
  753. X        refresh();
  754. X        getch();
  755. X        makebottom();
  756. X        return;
  757. X    }
  758. X
  759. X    mvprintw(5,0,"sector location is x=%d, y=%d",XREAL,YREAL);
  760. X    mvaddstr(7,0,"what x location to move to?");
  761. X    refresh();
  762. X    i = get_number();
  763. X
  764. X    if((i-(XREAL))>2||(i-(XREAL))<-2) {
  765. X        mvprintw(10,0,"can only move 2 sectors (you tried %hd)...--hit any key",i-(XREAL));
  766. X        refresh();
  767. X        getch();
  768. X        return;
  769. X    }
  770. X
  771. X    mvaddstr(10,0,"what y location to move to?");
  772. X    clrtoeol();
  773. X    refresh();
  774. X    j = get_number();
  775. X    if((j-(YREAL)>2)||((YREAL)-j>2)) {
  776. X        mvprintw(10,0,"sorry, can only move 2 sectors (you tried %hd)...--hit any key",j-(XREAL));
  777. X        refresh();
  778. X        getch();
  779. X    }
  780. X    else if(sct[i][j].owner!=country){
  781. X        mvaddstr(12,0,"sorry, you dont own it...");
  782. X        clrtoeol();
  783. X        refresh();
  784. X        getch();
  785. X    }
  786. X    /*need to check move cost > 0 for sector*/
  787. X    else if(movecost[i][j]<0){
  788. X        mvaddstr(12,0,"you can't enter there...");
  789. X        clrtoeol();
  790. X        refresh();
  791. X        getch();
  792. X    }
  793. X    else {
  794. X        ntn[country].tgold-=50*people;
  795. X        sct[XREAL][YREAL].people-=people;
  796. X        SADJCIV;
  797. X        sct[i][j].people+=people;
  798. X        SADJCIV2;
  799. X    }
  800. X}
  801. X
  802. Xarmygoto()
  803. X{
  804. X    short armynum=0,loop=0;
  805. X    armynum=getselunit();
  806. X    if((armynum<0)||(armynum>MAXARM)) armynum=0;
  807. X    else armynum++;
  808. X    /* move to next army with > 0 soldiers*/
  809. X    while ((armynum < MAXARM) && (ASOLD <= 0)) armynum++;
  810. X    if(armynum >= MAXARM)  {
  811. X        armynum=0;
  812. X        if(ASOLD <= 0) return(0);
  813. X    }
  814. X    /*move to correct location*/
  815. X    xcurs = AXLOC - xoffset;
  816. X    ycurs = AYLOC - yoffset;
  817. X    coffmap();
  818. X
  819. X    /*select correct unit*/
  820. X    selector=0;
  821. X    pager=0;
  822. X    while((getselunit() != armynum) && (loop++ < 500)) {
  823. X        selector+=2;
  824. X        if(selector>=10) {
  825. X            selector=0;
  826. X            pager+=1;
  827. X        }
  828. X    }
  829. X    return(1);
  830. X}
  831. X
  832. Xnavygoto()
  833. X{
  834. X    short nvynum=0,loop=0;
  835. X    nvynum=getselunit()-MAXARM;
  836. X    if((nvynum<0)||(nvynum>MAXNAVY)) nvynum=0;
  837. X    else nvynum++;
  838. X    /* move to next nvy with > 0 soldiers*/
  839. X    while ((nvynum < MAXNAVY) && (NMER+NWAR <= 0)) nvynum++;
  840. X    if(nvynum >= MAXNAVY) {
  841. X        nvynum=0;
  842. X        if(NMER+NWAR <= 0) return(0);
  843. X    }
  844. X    /*move to correct location*/
  845. X    xcurs = NXLOC - xoffset;
  846. X    ycurs = NYLOC - yoffset;
  847. X    coffmap();
  848. X    
  849. X    /*select correct unit*/
  850. X    selector=0;
  851. X    pager=0;
  852. X    while(((getselunit()-MAXARM) != nvynum) && (loop++ < 500)) {
  853. X        selector+=2;
  854. X        if(selector>=10) {
  855. X            selector=0;
  856. X            pager+=1;
  857. X        }
  858. X    }
  859. X    return(1);
  860. X}
  861. END_OF_commands.c
  862. if test 18869 -ne `wc -c <commands.c`; then
  863.     echo shar: \"commands.c\" unpacked with wrong size!
  864. fi
  865. # end of overwriting check
  866. fi
  867. if test -f magic.c -a "${1}" != "-c" ; then 
  868.   echo shar: Will not over-write existing file \"magic.c\"
  869. else
  870. echo shar: Extracting \"magic.c\" \(9841 characters\)
  871. sed "s/^X//" >magic.c <<'END_OF_magic.c'
  872. X/*conquer is copyrighted 1986 by Ed Barlow.
  873. X *  I spent a long time writing this code & I hope that you respect this.  
  874. X *  I give permission to alter the code, but not to copy or redistribute
  875. X *  it without my explicit permission.  If you alter the code, 
  876. X *  please document changes and send me a copy, so all can have it.  
  877. X *  This code, to the best of my knowledge works well,  but it is my first
  878. X *  'C' program and should be treated as such.  I disclaim any
  879. X *  responsibility for the codes actions (use at your own risk).  I guess
  880. X *  I am saying "Happy gaming", and am trying not to get sued in the process.
  881. X *                                                Ed
  882. X */
  883. X
  884. X/*create a new login for a new player*/
  885. X#include "header.h"
  886. X#include "data.h"
  887. X#include <ctype.h>
  888. X
  889. Xextern short country;
  890. Xextern short redraw;
  891. Xextern FILE *fexe;
  892. Xextern FILE *fnews;
  893. X
  894. X/*give player one new magic power in current magic (powers)*/
  895. X/*do nothing if that player has that power or it is not permitted*/
  896. X/*getmagic() returns the value of the power gained, and stores it in power*/
  897. X
  898. Xgetmagic()
  899. X{
  900. Xint newpower;
  901. X      newpower=1<<rand()%MAXPOWER;
  902. X    switch(newpower){
  903. X    case WARRIOR:
  904. X    case CAPTAIN:
  905. X    case WARLORD:
  906. X        if(magic(country,WARRIOR)!=1){
  907. X            ntn[country].powers|=WARRIOR;
  908. X            return(WARRIOR);
  909. X        }
  910. X        else if(magic(country,CAPTAIN)!=1){
  911. X            ntn[country].powers|=CAPTAIN;
  912. X            return(CAPTAIN);
  913. X        }
  914. X        else if(magic(country,WARLORD)!=1){
  915. X            ntn[country].powers|=WARLORD;
  916. X            return(WARLORD);
  917. X        }
  918. X        break;
  919. X    case MI_MONST:
  920. X    case AV_MONST:
  921. X    case MA_MONST:
  922. X        if(ntn[country].race!=ORC) return(0);
  923. X        if(magic(country,MI_MONST)!=1){
  924. X            ntn[country].powers|=MI_MONST;
  925. X            return(MI_MONST);
  926. X        }
  927. X        else if(magic(country,AV_MONST)!=1){
  928. X            ntn[country].powers|=AV_MONST;
  929. X            return(AV_MONST);
  930. X        }
  931. X        else if(magic(country,MA_MONST)==1){
  932. X            ntn[country].powers|=MA_MONST;
  933. X            return(MA_MONST);
  934. X        }
  935. X        break;
  936. X    case SPY:
  937. X    case KNOWALL:
  938. X    case DERVISH:
  939. X    case HIDDEN:
  940. X    case ARCHITECT:
  941. X    case URBAN:
  942. X    case THE_VOID:
  943. X    case HEALER:
  944. X    case ARCHER:
  945. X    case CAVALRY:
  946. X        if(magic(country,newpower)==1) return(0);
  947. X        ntn[country].powers|=newpower;
  948. X        return(newpower);
  949. X    case DESTROYER:
  950. X        if((ntn[country].race!=ELF)&&(magic(country,DESTROYER)!=1)){
  951. X            ntn[country].powers|=DESTROYER;
  952. X            return(DESTROYER);
  953. X        }
  954. X        break;
  955. X    case VAMPIRE:
  956. X        if((ntn[country].race!=ELF)&&(magic(country,VAMPIRE)!=1)){
  957. X            ntn[country].powers|=VAMPIRE;
  958. X            return(VAMPIRE);
  959. X        }
  960. X        break;
  961. X    case MINER:
  962. X        if((ntn[country].race!=ELF)&&(ntn[country].race!=DWARF)&&(magic(country,MINER)!=1)){
  963. X            ntn[country].powers|=MINER;
  964. X            return(MINER);
  965. X        }
  966. X        break;
  967. X    case STEEL:
  968. X        if(magic(country,STEEL)==1) return(0);
  969. X        if(magic(country,MINER)!=1) return(0);
  970. X        ntn[country].powers|=STEEL;
  971. X        return(STEEL);
  972. X    case BREEDER:
  973. X        if(magic(country,BREEDER)==1) return(0);
  974. X        if(ntn[country].race!=ORC) return(0);
  975. X        ntn[country].powers|=BREEDER;
  976. X        return(BREEDER);
  977. X    }
  978. X    return(0);
  979. X}
  980. X
  981. X/*form to interactively get a magic power*/
  982. Xdomagic()
  983. X{
  984. X      int x, count, done=0, loop=0, i, chance;
  985. X    long price;
  986. X    short isgod=0;
  987. X    if(country==0) {
  988. X        isgod=1;
  989. X        clear();
  990. X        mvaddstr(0,0,"WHAT NATION NUMBER:");
  991. X        refresh();
  992. X        country = get_number();
  993. X    }
  994. X
  995. X    while(done==0){
  996. X        done=1;
  997. X        clear();
  998. X        count=3;
  999. X        redraw=TRUE;
  1000. X        standout();
  1001. X        mvprintw(0,(COLS/2)-15,"MAGIC POWERS FOR %s",ntn[country].name);
  1002. X        standend();
  1003. X        /*print the powers that you have*/
  1004. X        if(magic(country,WARRIOR)==1)
  1005. X            mvaddstr(count++,0,"you have WARRIOR power (Fighter Level 1)");
  1006. X        if(magic(country,CAPTAIN)==1)
  1007. X            mvaddstr(count++,0,"you have CAPTAIN power (Fighter Level 2)");
  1008. X        if(magic(country,WARLORD)==1)
  1009. X            mvaddstr(count++,0,"you have WARLORD power (Fighter Level 3)");
  1010. X        if(magic(country,MI_MONST)==1)
  1011. X            mvaddstr(count++,0,"you have MINOR MONSTER power");
  1012. X        if(magic(country,AV_MONST)==1)
  1013. X            mvaddstr(count++,0,"you have AVERAGE MONSTER power");
  1014. X        if(magic(country,MA_MONST)==1) 
  1015. X            mvaddstr(count++,0,"you have MAJOR MONSTER power");
  1016. X        if(magic(country,SPY)==1) 
  1017. X            mvaddstr(count++,0,"you have SPY power");
  1018. X        if(magic(country,KNOWALL)==1)
  1019. X            mvaddstr(count++,0,"you have KNOWALL power");
  1020. X        if(magic(country,DERVISH)==1) 
  1021. X            mvaddstr(count++,0,"you have DERVISH power");
  1022. X        if(magic(country,DESTROYER)==1)
  1023. X            mvaddstr(count++,0,"you have DESTROYER power");
  1024. X        if(magic(country,HIDDEN)==1) 
  1025. X            mvaddstr(count++,0,"you have HIDDEN power");
  1026. X        if(magic(country,THE_VOID)==1)
  1027. X            mvaddstr(count++,0,"you have THE_VOID power");
  1028. X        if(magic(country,ARCHITECT)==1)
  1029. X            mvaddstr(count++,0,"you have ARCHITECT power");
  1030. X        if(magic(country,VAMPIRE)==1)
  1031. X            mvaddstr(count++,0,"you have VAMPIRE power");
  1032. X        if(magic(country,HEALER)==1)
  1033. X            mvaddstr(count++,0,"you have HEALER power");
  1034. X        if(magic(country,MINER)==1) 
  1035. X            mvaddstr(count++,0,"you have MINER power");
  1036. X        if(magic(country,URBAN)==1)
  1037. X            mvaddstr(count++,0,"you have URBAN power");
  1038. X        if(magic(country,STEEL)==1)
  1039. X            mvaddstr(count++,0,"you have STEEL power");
  1040. X        if(magic(country,ARCHER)==1)
  1041. X            mvaddstr(count++,0,"you have ARCHER power");
  1042. X        if(magic(country,CAVALRY)==1)
  1043. X            mvaddstr(count++,0,"you have CAVALRY power");
  1044. X        if(magic(country,BREEDER)==1)
  1045. X            mvaddstr(count++,0,"you have BREEDER power");
  1046. X
  1047. X        standout();
  1048. X            
  1049. X        if (count-3 >= MAXPOWER) {
  1050. X            mvaddstr(count++,0,"You have all the available powers");
  1051. X            refresh();
  1052. X            getch();
  1053. X        }
  1054. X        price = JWL_MGK;
  1055. X        for (i=1; i<count-3; i++) {
  1056. X            price <<= 1;
  1057. X            if (price > 500000000)
  1058. X                break;
  1059. X        }
  1060. X
  1061. X        if((ntn[country].race==ORC)&& ntn[country].jewels>=100000L){
  1062. X            if(magic(country,MA_MONST)==1) {
  1063. X            mvaddstr(count++,0,"  You have a 10 percent chance for 100K Jewels to take over other orcs");
  1064. X            chance=10;
  1065. X            } else if(magic(country,AV_MONST)==1) {
  1066. X            mvaddstr(count++,0,"  You have a 6 percent chance for 100K Jewels to take over other orcs");
  1067. X            chance=6;
  1068. X            } else if(magic(country,MI_MONST)==1){
  1069. X            mvaddstr(count++,0,"  You have a 3 percent chance for 100K Jewels to take over other orcs");
  1070. X            chance=3;
  1071. X            }
  1072. X            mvprintw(count++,0,"DO YOU WISH TO TAKE OVER AN ORC NPC NATION (enter y or n):");
  1073. X            refresh();
  1074. X            if(getch()=='y'){
  1075. X                done=0;
  1076. X                mvaddstr(count++,0,"  What orc nation:");
  1077. X                refresh();
  1078. X                i=get_number();
  1079. X                if(ntn[i].race==ORC){
  1080. X                    ntn[country].jewels-=100000L;
  1081. X                    if(i=takeover(chance,i)==1)
  1082. X                     mvprintw(count++,0," Successful: %d",i);
  1083. X                }
  1084. X                 else mvaddstr(count++,0,"  Wrong Race");
  1085. X            }
  1086. X        }
  1087. X
  1088. X        count++;
  1089. X        if(ntn[country].jewels>=price) {
  1090. X            mvprintw(count++,0,"YOU CURRENTLY HAVE %ld JEWELS IN YOUR TREASURY",ntn[country].jewels);
  1091. X            mvprintw(count++,0,"DO YOU WISH TO BUY A RANDOM NEW POWER FOR %ld JEWELS (enter y or n):",price);
  1092. X            standend();
  1093. X            refresh();
  1094. X            if(getch()=='y'){
  1095. X                done=0;
  1096. X                loop = 0;
  1097. X                while(loop++ < 500) if((x=getmagic())!=0){
  1098. X                    ntn[country].jewels -= price;
  1099. X                    CHGMGK;
  1100. X                    exenewmgk(x);
  1101. X                    refresh();
  1102. X                    break;
  1103. X                }
  1104. X                if (loop >= 500)
  1105. X                    mvaddstr(count++,0,"You have too many powers!");
  1106. X            }
  1107. X        } else {
  1108. X            mvaddstr(count++,0,"NOT ENOUGH JEWELS TO PURCHASE NEW MAGIC -- hit any key");
  1109. X            refresh();
  1110. X            getch();
  1111. X        }
  1112. X    }
  1113. X    if(isgod==1) country=0;
  1114. X}
  1115. X
  1116. X
  1117. X/*do magic for both npcs and pcs in update*/
  1118. X/*if target is 0 then it is update and target will be picked randomly*/
  1119. Xint
  1120. Xtakeover(percent,target)
  1121. X{
  1122. Xint loop=1,y,save,isupdate=0;
  1123. X    save=country;
  1124. X    if(target==country) return(0);
  1125. X    if(target==0) isupdate=1;
  1126. X    country=target;
  1127. X    if(rand()%100<percent){
  1128. X        loop=0;
  1129. X        y=0;
  1130. X        if (target==0) while(loop==0){
  1131. X            y++;
  1132. X            country=rand()%MAXNTN;
  1133. X            if((ntn[country].race==ntn[save].race)
  1134. X            &&(ntn[country].active>=2)) loop=1;
  1135. X            else if(y>=500) {
  1136. X                country=save;
  1137. X                return(0);
  1138. X            }
  1139. X        }
  1140. X        sct[ntn[country].capx][ntn[country].capy].owner=save;
  1141. X        if(isupdate==1){
  1142. X        printf("nation %s taken over by %s\n",ntn[country].name,ntn[save].name);
  1143. X        fprintf(fnews,"1.\tnation %s taken over by %s\n",ntn[country].name,ntn[save].name);
  1144. X        }
  1145. X        else DESTROY;
  1146. X        destroy();
  1147. X        y=country;
  1148. X        country=save;
  1149. X        return(y);
  1150. X    }
  1151. X    country=save;
  1152. X    return(0);
  1153. X}
  1154. X
  1155. X/*execute new magic*/
  1156. Xexenewmgk(newpower)
  1157. X{
  1158. X    short x,y;
  1159. X    switch(newpower){
  1160. X        case WARRIOR:
  1161. X            ntn[country].aplus+=10;
  1162. X            ntn[country].dplus+=10;
  1163. X            break;
  1164. X        case CAPTAIN:
  1165. X            ntn[country].aplus+=10;
  1166. X            ntn[country].dplus+=10;
  1167. X            break;
  1168. X        case WARLORD:
  1169. X            ntn[country].aplus+=10;
  1170. X            ntn[country].dplus+=10;
  1171. X            break;
  1172. X        case HEALER:
  1173. X            if(ntn[country].race==ORC) {
  1174. X                if(ntn[country].repro<=11)
  1175. X                    ntn[country].repro+=2;
  1176. X                else    ntn[country].repro=13;
  1177. X            }
  1178. X            else if(ntn[country].repro<=8){
  1179. X                ntn[country].repro=10;
  1180. X            }
  1181. X            else if(ntn[country].repro==9){
  1182. X                ntn[country].repro=10;
  1183. X                ntn[country].dplus+=5;
  1184. X            }
  1185. X            else if(ntn[country].repro>=10){
  1186. X                ntn[country].dplus+=10;
  1187. X            }
  1188. X            break;
  1189. X        case DESTROYER:
  1190. X            for(x=ntn[country].capx-3;x<=ntn[country].capx+3;x++) {
  1191. X                for(y=ntn[country].capy-3;y<=ntn[country].capy+3;y++){
  1192. X                    if((ONMAP)
  1193. X                    &&(sct[x][y].altitude!=WATER)
  1194. X                    &&(isdigit(sct[x][y].vegetation)==0)){
  1195. X                        sct[x][y].vegetation=DESERT;
  1196. X                        sct[x][y].designation=DESERT;
  1197. X                    }
  1198. X                }
  1199. X            }
  1200. X              updmove(ntn[country].race);
  1201. X            break;
  1202. X        case DERVISH:
  1203. X              updmove(ntn[country].race);
  1204. X              break;
  1205. X        case MI_MONST:
  1206. X        case AV_MONST:
  1207. X        case MA_MONST:
  1208. X        case SPY:
  1209. X        case KNOWALL:
  1210. X        case HIDDEN:
  1211. X        case THE_VOID:
  1212. X        case ARCHITECT:
  1213. X        case MINER:
  1214. X            break;
  1215. X        case VAMPIRE:
  1216. X            ntn[country].aplus-=35;
  1217. X            ntn[country].dplus-=35;
  1218. X            ntn[country].maxmove-=2;
  1219. X            break;
  1220. X        case URBAN:
  1221. X            if(ntn[country].race==ORC) {
  1222. X                ntn[country].repro+=3;
  1223. X                if(ntn[country].repro>=13){
  1224. X                ntn[country].maxmove+=2*(ntn[country].repro-13);
  1225. X                ntn[country].repro=13;
  1226. X                }
  1227. X            }
  1228. X            else if(ntn[country].repro<=9){
  1229. X                ntn[country].repro+=3;
  1230. X            }
  1231. X            else {
  1232. X                ntn[country].maxmove+=2*(ntn[country].repro-9);
  1233. X                ntn[country].repro=12;
  1234. X            }
  1235. X            break;
  1236. X        case STEEL:
  1237. X            break;
  1238. X        case ARCHER:
  1239. X            ntn[country].dplus+=10;
  1240. X            break;
  1241. X        case CAVALRY:
  1242. X            ntn[country].aplus+=10;
  1243. X            ntn[country].maxmove+=6;
  1244. X            break;
  1245. X        case BREEDER:
  1246. X            ntn[country].repro+=3;
  1247. X            ntn[country].dplus-=10;
  1248. X            ntn[country].dplus-=10;
  1249. X            break;
  1250. X    }
  1251. X}
  1252. END_OF_magic.c
  1253. if test 9841 -ne `wc -c <magic.c`; then
  1254.     echo shar: \"magic.c\" unpacked with wrong size!
  1255. fi
  1256. # end of overwriting check
  1257. fi
  1258. if test -f main.c -a "${1}" != "-c" ; then 
  1259.   echo shar: Will not over-write existing file \"main.c\"
  1260. else
  1261. echo shar: Extracting \"main.c\" \(20136 characters\)
  1262. sed "s/^X//" >main.c <<'END_OF_main.c'
  1263. X/*conquer is copyrighted 1986 by Ed Barlow.
  1264. X *  I spent a long time writing this code & I hope that you respect this.  
  1265. X *  I give permission to alter the code, but not to copy or redistribute
  1266. X *  it without my explicit permission.  If you alter the code, 
  1267. X *  please document changes and send me a copy, so all can have it.  
  1268. X *  This code, to the best of my knowledge works well,  but it is my first
  1269. X *  'C' program and should be treated as such.  I disclaim any
  1270. X *  responsibility for the codes actions (use at your own risk).  I guess
  1271. X *  I am saying "Happy gaming", and am trying not to get sued in the process.
  1272. X *                                                Ed
  1273. X */
  1274. X
  1275. X/*include files*/
  1276. X#include <ctype.h>
  1277. X#include "header.h"
  1278. X#include "data.h"
  1279. X#include <signal.h>
  1280. X#include <fcntl.h>
  1281. X#include  <pwd.h>
  1282. X
  1283. X/*initialization data*/
  1284. X/*Movement costs*/
  1285. Xchar *ele=       "#^%-~";
  1286. Xchar *elename[]= {  "PEAK", "MOUNTAIN", "HILL", "FLAT","WATER"};
  1287. Xchar *veg=       "VDW46973JSI~";
  1288. Xchar *vegname[]= { "VOLCANO", "DESERT", "WASTE", "BARREN(4)", "LT VEG(6)",
  1289. X"GOOD (9)", "WOOD (7)", "FOREST(3)", "JUNGLE", "SWAMP", "ICE", "NONE"};
  1290. Xchar *numbers=   "0123456789";
  1291. Xchar *Class[]= { "NPC", "king", "emperor", "wizard", "priest", "pirate", 
  1292. X"trader", "tyrant", "demon", "dragon", "shadow"};
  1293. Xchar *races[]= { "GOD","ORC","ELF","DWARF","LIZARD",
  1294. X"HUMAN","PIRATE","BARBARIAN","NOMAD","UNKNOWN"};
  1295. Xchar *diploname[]= { "UNMET", "CONFEDERACY", "ALLIED", "FRIENDLY",
  1296. X"NEUTRAL", "HOSTILE", "WAR", "JIHAD"};
  1297. Xchar *soldname[]= { "","MARCH","SCOUT","ATTACK","DEFEND","GARRISON"};
  1298. Xchar *des=       "cCmfx$!-";
  1299. Xchar *desname[]= {"CITY", "CAPITOL", "MINE", "FARM", "DEVASTATED", "GOLDMINE", 
  1300. X"CASTLE", "NODESIG", "PEAK", "WATER"};
  1301. Xchar    *exefile =  "execute";
  1302. Xchar    *datafile = "data";
  1303. Xchar    *msgfile =  "messages";
  1304. Xchar    *npcsfile = "nations";
  1305. Xchar    *helpfile = "help";
  1306. Xchar    *newsfile = "news";
  1307. X
  1308. X/*Declarations*/
  1309. Xstruct s_sector sct[MAPX][MAPY];
  1310. Xstruct nation ntn[NTOTAL];   /* player nation stats */
  1311. X/*is sector occupied by an army?*/
  1312. Xchar    occ[MAPX][MAPY];
  1313. Xshort movecost[MAPX][MAPY];
  1314. Xextern int armornvy;
  1315. Xlong startgold=0;
  1316. X
  1317. X/*offset of upper left hand corner*/
  1318. Xshort xoffset=0,yoffset=0;
  1319. X/*current cursor postion (relative to 00 in upper corner)*/
  1320. X/*    position is 2*x,y*/
  1321. Xshort xcurs=0,ycurs=0;
  1322. X/*redraw map in this turn if redraw is a 1*/
  1323. Xshort redraw=TRUE;
  1324. X/*1 if you have quit*/
  1325. Xint done=0;
  1326. X/*display state*/
  1327. Xshort hilmode=0;   /*highlight modes: 0=owned sectors, 1= armies, 2=none*/
  1328. Xshort dismode=2;   /*display mode: 1=vegetation, 2=desig, 3=contour*/
  1329. X/*         4=armies/navies, 5=commodities, 6=fertility*/
  1330. Xshort selector=0;  /*selector (y vbl) for which army/navy... is "picked"*/
  1331. Xshort pager=0;     /*pager for selector 0,1,2,3*/
  1332. X/* nation id of owner*/
  1333. Xshort country=0;
  1334. X
  1335. XFILE *fexe, *fopen();
  1336. X
  1337. Xmain(argc,argv)
  1338. Xint argc;
  1339. Xchar **argv;
  1340. X{
  1341. X    register int i;
  1342. X    char *name;
  1343. X    void srand();
  1344. X    int getopt();
  1345. X    char passwd[20];
  1346. X    long time();
  1347. X    /*mflag = makeworld, a=add player, x=execute, p=print, h=help, s=score*/
  1348. X    int mflag, aflag, xflag, pflag, sflag;
  1349. X    char string[80];
  1350. X    extern char *optarg;
  1351. X    char defaultdir[256];
  1352. X    int uid;
  1353. X    struct passwd *getpwnam();
  1354. X
  1355. X    mflag = aflag = xflag = pflag = sflag = 0;
  1356. X    srand((unsigned) time((long *) 0));
  1357. X    strcpy(defaultdir, DEFAULTDIR);
  1358. X    name = string;
  1359. X    *name = 0;
  1360. X
  1361. X    /* process the command line arguments */
  1362. X    while((i=getopt(argc,argv,"maxphn:d:s"))!=EOF) switch(i){
  1363. X    /* process the command line arguments */
  1364. X    case 'm':  /* make a new world*/
  1365. X        mflag++;
  1366. X        break;
  1367. X    case 'a': /* anyone with password can add player*/
  1368. X        aflag++;
  1369. X        break;
  1370. X    case 'x': /* execute program*/
  1371. X        xflag++;
  1372. X        break;
  1373. X    case 'p': /* print the map*/
  1374. X        pflag++;
  1375. X        break;
  1376. X    case 'h': /* execute help program*/
  1377. X        initscr();
  1378. X        savetty();
  1379. X        noecho();
  1380. X        crmode();            /* cbreak mode */
  1381. X        signal(SIGINT,SIG_IGN);        /* disable keyboard signals */
  1382. X        signal(SIGQUIT,SIG_IGN);
  1383. X        help();
  1384. X        endwin();
  1385. X        putchar('\n');
  1386. X        exit(1);
  1387. X    case 'd':
  1388. X        strcpy(defaultdir, optarg);
  1389. X        break;
  1390. X    case 'n':
  1391. X        strcpy(name, optarg);
  1392. X        break;
  1393. X        case 's': /*print the score*/
  1394. X        sflag++;
  1395. X        break;
  1396. X    case '?': /*  print out command line arguments */
  1397. X        printf("Cmd line format: conquer [-maxdhp]\n");
  1398. X        printf("\t-a       add new player\n");
  1399. X        printf("\t-d DIR   to use play different game\n");
  1400. X        printf("\t-h       print help text\n");
  1401. X        printf("\t-m       make a world\n");
  1402. X        printf("\t-n NAT   play as nation NAT\n");
  1403. X        printf("\t-p       print a map\n");
  1404. X        printf("\t-x       execute program\n");
  1405. X        exit(0);
  1406. X    };
  1407. X
  1408. X    /* now that we have parsed the args, we can got to the
  1409. X     * dir where the files are kept and do some work.
  1410. X     */
  1411. X    if (chdir(defaultdir)) {
  1412. X        printf("unable to change dir to %s\n",defaultdir);
  1413. X        exit(1);
  1414. X    }
  1415. X    if (mflag) {
  1416. X        makeworld();
  1417. X        exit(0);
  1418. X    }
  1419. X
  1420. X    /* read data*/
  1421. X    readdata();
  1422. X    verifydata( __FILE__, __LINE__ );
  1423. X
  1424. X    if (aflag) { /* a new player */
  1425. X        if(strncmp(crypt(getpass("\nwhat is super user password:"),SALT),ntn[0].passwd,PASSLTH)!=0) {
  1426. X            printf("sorry, must be super user to add player\n");
  1427. X            exit(1);
  1428. X        }
  1429. X        newlogin();
  1430. X        exit(1);
  1431. X    } else if (pflag) {    /* print a map of the game */
  1432. X        if(strncmp(crypt(getpass("\nwhat is super user password:"),SALT),ntn[0].passwd,PASSLTH)!=0) {
  1433. X            printf("sorry, must be super user to get map\n");
  1434. X            exit(1);
  1435. X        }
  1436. X        printf("what type of map\noptions are\n");
  1437. X        printf("\t1) altitudes\n\t2) vegetations\n");
  1438. X        printf("\t3) nations\n\n");
  1439. X        printf("\tINPUT:");
  1440. X        scanf("%hd",&dismode);
  1441. X        if(dismode==1) printele();
  1442. X        else if(dismode==2) printveg();
  1443. X        else pr_ntns();
  1444. X        exit(1);
  1445. X    } else if (sflag) {    /* update the game */
  1446. X        printscore();
  1447. X        exit(0);
  1448. X    } else if (xflag) {    /* update the game */
  1449. X        uid=geteuid();
  1450. X        if ( uid != (getpwnam(LOGIN))->pw_uid ){
  1451. X            printf("sorry -- your uid is invalid for updating\n");
  1452. X            printf("you need to be logged in as %s\n",LOGIN);
  1453. X            exit(-100); /* boom */
  1454. X        }
  1455. X        update();
  1456. X        writedata();
  1457. X        exit(1);
  1458. X    }
  1459. X
  1460. X    /* must be a normal interactive game */
  1461. X    armornvy=AORN;
  1462. X
  1463. X    /* identify the player and the country he represents */
  1464. X
  1465. X    /* get nation name either from command line or by asking
  1466. X         *     if you fail will give you the name of administrator of game
  1467. X         */
  1468. X
  1469. X    /* verify existence of nation*/
  1470. X    printf("conquer: %s copyrighted by Ed Barlow (1986)\n",VERSION);
  1471. X    if (*name == 0) {
  1472. X        printf("what nation would you like to be:");
  1473. X        scanf("%s",name);
  1474. X    }
  1475. X    if(strcmp(name,"god")==0) strcpy(name,"unowned");
  1476. X    country=(-1);
  1477. X    for(i=0;i<NTOTAL;i++)
  1478. X        if(strcmp(name,ntn[i].name)==0) country=i;
  1479. X
  1480. X    if(country==(-1)) {
  1481. X        printf("name not found\n");
  1482. X        printf("\nfor rules type <conquer -h>");
  1483. X        printf("\nfor more information please contact %s\n",OWNER);
  1484. X        return;
  1485. X    }
  1486. X
  1487. X    /*get encrypted password*/
  1488. X    strcpy(passwd,crypt(getpass("\nwhat is your password:"),SALT));
  1489. X    if((strncmp(passwd,ntn[country].passwd,PASSLTH)!=0)
  1490. X    &&(strncmp(passwd,ntn[0].passwd,PASSLTH)!=0)) {
  1491. X        strcpy(passwd,crypt(getpass("\nerror: reenter your password:"),SALT));
  1492. X        if((strncmp(passwd,ntn[country].passwd,PASSLTH)!=0)
  1493. X        &&(strncmp(passwd,ntn[0].passwd,PASSLTH)!=0)) {
  1494. X            printf("\nsorry:");
  1495. X            printf("\nfor rules type <conquer -h>");
  1496. X            printf("\nfor more information on the system please contact %s\n",OWNER);
  1497. X            exit(1);
  1498. X        }
  1499. X    }
  1500. X
  1501. X    /* check if user is super-user nation[0] */
  1502. X    /*     else setup cursor to capitol*/
  1503. X    if(country==0) {
  1504. X        printf("welcome super user\n");
  1505. X        xcurs=1;
  1506. X        xoffset=0;
  1507. X        ycurs=1;
  1508. X        yoffset=0;
  1509. X    }
  1510. X    else {
  1511. X        printf("\nverifing that nation %s exists\n",ntn[country].name);
  1512. X        startgold = ntn[country].tgold;
  1513. X        execute();
  1514. X        if(ntn[country].capx>15) {
  1515. X            xcurs=15;
  1516. X            xoffset= (ntn[country].capx-15);
  1517. X        }
  1518. X        else {
  1519. X            xcurs= ntn[country].capx;
  1520. X            xoffset= 0;
  1521. X        }
  1522. X        if(ntn[country].capy>10) {
  1523. X            ycurs=10;
  1524. X            yoffset= (ntn[country].capy-10);
  1525. X        }
  1526. X        else {
  1527. X            yoffset= 0;
  1528. X            ycurs= ntn[country].capy;
  1529. X        }
  1530. X    }
  1531. X
  1532. X    updmove(ntn[country].race);
  1533. X
  1534. X    /* open output for future printing*/
  1535. X    {
  1536. X        char filename[80];
  1537. X        sprintf(filename,"%s%d",exefile,country);
  1538. X        if ((fexe=fopen(filename,"a"))==NULL) {
  1539. X            beep();
  1540. X            printf("error opening %s\n",filename);
  1541. X            exit(1);
  1542. X        }
  1543. X    }
  1544. X
  1545. X    /* SET UP THE SCREEN */
  1546. X    printf("about to set up the screen");
  1547. X    initscr();
  1548. X    crmode();            /* cbreak mode */
  1549. X    signal(SIGINT,SIG_IGN);        /* disable keyboard signals */
  1550. X    signal(SIGQUIT,SIG_IGN);
  1551. X
  1552. X    prep();
  1553. X    noecho();
  1554. X
  1555. X    /*main while routine*/
  1556. X    done=0;
  1557. X    while (done==0)
  1558. X    {
  1559. X        /* check if cursor is out of bounds*/
  1560. X        coffmap();
  1561. X        /*get commands, make moves and input command*/
  1562. X        parse();
  1563. X    }
  1564. X
  1565. X    if(country==0) writedata();
  1566. X    else {
  1567. X    fprintf(fexe,"L_NGOLD\t%d \t%d \t%ld \t0 \t0 \t%s\n",
  1568. X        XNAGOLD ,country,ntn[country].tgold,"null");
  1569. X    fprintf(fexe,"L_NIRON\t%d \t%d \t%ld \t0 \t0 \t%s\n",
  1570. X        XNAIRON ,country,ntn[country].tiron,"null");
  1571. X    fprintf(fexe,"L_NJWLS\t%d \t%d \t%ld \t0 \t0 \t%s\n",
  1572. X        XNARGOLD ,country,ntn[country].jewels,"null");
  1573. X    }
  1574. X    /*done so quit*/
  1575. X    clear();
  1576. X    printw("quitting\n");
  1577. X    refresh();
  1578. X    nocrmode();
  1579. X    endwin();
  1580. X    fclose(fexe);
  1581. X    exit(1);
  1582. X}
  1583. X
  1584. X/*make the bottom of the screen*/
  1585. Xmakebottom()
  1586. X{
  1587. X    move(LINES-4,0);
  1588. X    clrtoeol();
  1589. X    mvprintw(LINES-3,0,"Conquer: %s",VERSION);
  1590. X    clrtoeol();
  1591. X    mvaddstr(LINES-1,0,"  type ? for help");
  1592. X    clrtoeol();
  1593. X    mvaddstr(LINES-2,0,"  type Q to quit");
  1594. X    clrtoeol();
  1595. X    if(country==0) mvaddstr(LINES-3,COLS-20,"nation..GOD  ");
  1596. X    else {
  1597. X        mvprintw(LINES-3,COLS-20,"nation...%s",ntn[country].name);
  1598. X        mvprintw(LINES-2,COLS-20,"treasury.%ld",ntn[country].tgold);
  1599. X        mvprintw(LINES-1,COLS-20,"score....%d",ntn[country].score);
  1600. X    }
  1601. X}
  1602. X
  1603. X/* parse */
  1604. Xparse()
  1605. X{
  1606. X    register int i;
  1607. X    char name[20];
  1608. X    char passwd[12];
  1609. X    int ocountry;
  1610. X
  1611. X    switch(getch()) {
  1612. X    case ' ':    /*redraw the screen*/
  1613. X        redraw=TRUE;
  1614. X        break;
  1615. X    case 'a':    /*army report*/
  1616. X        redraw=TRUE;
  1617. X        armyrpt();
  1618. X        break;
  1619. X    case 'A':    /*adjust army*/
  1620. X        redraw=TRUE;
  1621. X        adjarm();
  1622. X        break;
  1623. X    case 'b':    /*move south west*/
  1624. X        pager=0;
  1625. X        selector=0;
  1626. X        xcurs--;
  1627. X        ycurs++;
  1628. X        break;
  1629. X    case 'B':    /*budget*/
  1630. X        redraw=TRUE;
  1631. X        budget();
  1632. X        break;
  1633. X    case 'c':    /*change nation stats*/
  1634. X        redraw=TRUE;
  1635. X        change();
  1636. X        break;
  1637. X    case 'C':    /*construct*/
  1638. X        construct();
  1639. X        break;
  1640. X    case 'd':    /*change display*/
  1641. X        newdisplay();
  1642. X        break;
  1643. X    case 'D':    /*draft*/
  1644. X        draft();
  1645. X        break;
  1646. X    case 'f': /*report on ships and load/unload*/
  1647. X        redraw=TRUE;
  1648. X        fleetrpt();
  1649. X        break;
  1650. X    case 'F':    /*go to next army*/
  1651. X        navygoto();
  1652. X        break;
  1653. X    case 'G':    /*go to next army*/
  1654. X        armygoto();
  1655. X        break;
  1656. X    case 'H':    /*scroll west*/
  1657. X        pager=0;
  1658. X        selector=0;
  1659. X        xcurs-=((COLS-22)/4);
  1660. X        break;
  1661. X    case 'h':    /*move west*/
  1662. X        pager=0;
  1663. X        selector=0;
  1664. X        xcurs--;
  1665. X        break;
  1666. X    case 'J':    /*scroll down*/
  1667. X        pager=0;
  1668. X        selector=0;
  1669. X        ycurs+=((SCREEN_Y_SIZE)/2);
  1670. X        break;
  1671. X    case 'j':    /*move down*/
  1672. X        pager=0;
  1673. X        selector=0;
  1674. X        ycurs++;
  1675. X        break;
  1676. X    case 'k':    /*move up*/
  1677. X        pager=0;
  1678. X        selector=0;
  1679. X        ycurs--;
  1680. X        break;
  1681. X    case 'K':    /*scroll up*/
  1682. X        pager=0;
  1683. X        selector=0;
  1684. X        ycurs-=((SCREEN_Y_SIZE)/2);
  1685. X        break;
  1686. X    case 'l':    /*move east*/
  1687. X        pager=0;
  1688. X        selector=0;
  1689. X        xcurs++;
  1690. X        break;
  1691. X    case 'L':    /*scroll east*/
  1692. X        pager=0;
  1693. X        selector=0;
  1694. X        xcurs+=((COLS-22)/4);
  1695. X        break;
  1696. X    case 'm':     /*move selected item to new x,y */
  1697. X        mymove();
  1698. X        prep();
  1699. X        pager=0;
  1700. X        selector=0;
  1701. X        break;
  1702. X    case 'M':     /*magic*/
  1703. X        redraw=TRUE;
  1704. X        domagic();
  1705. X        break;
  1706. X    case 'n':    /*move south-east*/
  1707. X        pager=0;
  1708. X        selector=0;
  1709. X        ycurs++;
  1710. X        xcurs++;
  1711. X        break;
  1712. X    case 'N':    /*read newspaper */
  1713. X        redraw=TRUE;
  1714. X        newspaper();
  1715. X        break;
  1716. X    case 'p':    /*pick*/
  1717. X        selector+=2;
  1718. X        if(selector>=10) {
  1719. X            selector=0;
  1720. X            pager+=1;
  1721. X        }
  1722. X        /*current selected unit is selector/2+5*pager*/
  1723. X        if((selector/2)+(pager*5)>=units_in_sector(XREAL,YREAL,country)) {
  1724. X            pager=0;
  1725. X            selector=0;
  1726. X        }
  1727. X        break;
  1728. X    case 'P':    /*production*/
  1729. X        redraw=TRUE;
  1730. X        produce();
  1731. X        break;
  1732. X    case 'Q':    /*quit*/
  1733. X    case 'q':    /*quit*/
  1734. X        done=1;
  1735. X        break;
  1736. X    case 'r':     /*redesignate*/
  1737. X        redesignate();
  1738. X        makemap();
  1739. X        makebottom();
  1740. X        break;
  1741. X        /*list*/
  1742. X    case 'R':     /*Read Messages*/
  1743. X        redraw=TRUE;
  1744. X        rmessage();
  1745. X        refresh();
  1746. X        break;
  1747. X    case 's':    /*score*/
  1748. X        redraw=TRUE;
  1749. X        showscore();
  1750. X        break;
  1751. X    case 'S':    /*diplomacy screens*/
  1752. X        diploscrn();
  1753. X        redraw=TRUE;
  1754. X        break;
  1755. X    case 'u':    /*move north-east*/
  1756. X        pager=0;
  1757. X        selector=0;
  1758. X        ycurs--;
  1759. X        xcurs++;
  1760. X        break;
  1761. X    case 'W':     /*message*/
  1762. X        redraw=TRUE;
  1763. X        wmessage();
  1764. X        break;
  1765. X    case 'y':    /*move north-west*/
  1766. X        pager=0;
  1767. X        selector=0;
  1768. X        ycurs--;
  1769. X        xcurs--;
  1770. X        break;
  1771. X    case 'Z':    /*move civilians up to 2 spaces*/
  1772. X        redraw=TRUE;
  1773. X        moveciv();
  1774. X        break;
  1775. X    case 'z':    /*login as new user */
  1776. X        clear();
  1777. X        if(country != 0) {
  1778. X        redraw=TRUE;
  1779. X        fprintf(fexe,"L_NGOLD\t%d \t%d \t%ld \t0 \t0 \t%s\n",
  1780. X            XNAGOLD ,country,ntn[country].tgold,"null");
  1781. X        fprintf(fexe,"L_NIRON\t%d \t%d \t%ld \t0 \t0 \t%s\n",
  1782. X            XNAIRON ,country,ntn[country].tiron,"null");
  1783. X        fprintf(fexe,"L_NJWLS\t%d \t%d \t%ld \t0 \t0 \t%s\n",
  1784. X            XNARGOLD ,country,ntn[country].jewels,"null");
  1785. X        }
  1786. X        else mvaddstr(2,0,"SUPER-USER: YOUR CHANGES WILL NOT BE SAVED IF YOU DO THIS!!!");
  1787. X        standout();
  1788. X        mvaddstr(0,0,"change login to : ");
  1789. X        standend();
  1790. X        refresh();
  1791. X        echo();
  1792. X        scanw("%s",name);
  1793. X        noecho();
  1794. X
  1795. X        ocountry=country;
  1796. X        country=(-1);
  1797. X        if(strcmp(name,"god")==0) country=0;
  1798. X        else for(i=1;i<NTOTAL;i++)
  1799. X            if((strcmp(name,ntn[i].name)==0)&&(ntn[i].active>=1))
  1800. X                country=i;
  1801. X
  1802. X        if(country==(-1)) {
  1803. X            mvaddstr(2,0,"name not found");
  1804. X            country=ocountry;
  1805. X            break;
  1806. X        }
  1807. X
  1808. X        /*get password*/
  1809. X        mvaddstr(2,0,"what is your password:");
  1810. X        refresh();
  1811. X        getstr(passwd);
  1812. X        strcpy(name,crypt(passwd,SALT));
  1813. X
  1814. X        if((strncmp(name,ntn[country].passwd,PASSLTH)!=0)
  1815. X        &&(strncmp(name,ntn[0].passwd,PASSLTH)!=0)){
  1816. X            mvaddstr(3,0,"sorry:");
  1817. X            refresh();
  1818. X            country=ocountry;
  1819. X            break;
  1820. X        }
  1821. X
  1822. X        fclose(fexe);
  1823. X        /* open output for future printing*/
  1824. X            sprintf(name,"%s%d",exefile,country);
  1825. X            if ((fexe=fopen(name,"a"))==NULL) {
  1826. X            beep();
  1827. X               printf("error opening %s\n",name);
  1828. X               exit(1);
  1829. X            }
  1830. X
  1831. X        readdata();
  1832. X        startgold = ntn[country].tgold;
  1833. X        execute();
  1834. X
  1835. X        updmove(ntn[country].race);
  1836. X        /*go to that nations capital*/
  1837. X        if(country!=0) {
  1838. X            if(ntn[country].capx>15) {
  1839. X                xcurs=15;
  1840. X                xoffset= (ntn[country].capx-15);
  1841. X            }
  1842. X            else {
  1843. X                xcurs= ntn[country].capx;
  1844. X                xoffset= 0;
  1845. X            }
  1846. X            if(ntn[country].capy>10) {
  1847. X                ycurs=10;
  1848. X                yoffset= (ntn[country].capy-10);
  1849. X            }
  1850. X            else {
  1851. X                yoffset= 0;
  1852. X                ycurs= ntn[country].capy;
  1853. X            }
  1854. X        }
  1855. X        break;
  1856. X    case '?':    /*display help screen*/
  1857. X        redraw=TRUE;
  1858. X        help();
  1859. X        break;
  1860. X    default:
  1861. X        beep();
  1862. X    }
  1863. X}
  1864. X
  1865. Xmakeside()
  1866. X{
  1867. X    int i;
  1868. X    int armbonus=0;
  1869. X    int found=0,nvyfnd=0;
  1870. X    int enemy;
  1871. X    int y;
  1872. X    short armynum;
  1873. X    short nvynum;
  1874. X    int count;
  1875. X    int nfound=0;
  1876. X
  1877. X    /*clear side if you cant see it as you are out of bounds*/
  1878. X    if(inch()==' ') {
  1879. X        for(i=0;i<LINES-3;i++){
  1880. X            move(i,COLS-21);
  1881. X            clrtoeol();
  1882. X        }
  1883. X        return;
  1884. X    }
  1885. X
  1886. X    /*clear top right hand side each new sector*/
  1887. X    for(count=0;count<11;count++){
  1888. X        move(count,COLS-21);
  1889. X        clrtoeol();
  1890. X    }
  1891. X
  1892. X    /*check for your armies*/
  1893. X    count=units_in_sector(XREAL,YREAL,country);
  1894. X    if(pager*5>count) pager=0;
  1895. X
  1896. X    /*first army found is #0*/
  1897. X    /*show armies / navies in range pager*5 to pager*5 + 4*/
  1898. X    /*so if pager=0 show 0 to 4, pager=2 show 10 to 14*/
  1899. X    /*current selected unit is selector/2+5*pager*/
  1900. X
  1901. X    if(count>(5+(pager*5))) mvaddstr(10,COLS-20,"MORE...");
  1902. X
  1903. X    nfound=0;
  1904. X    for(armynum=0;armynum<MAXARM;armynum++){
  1905. X        if((ASOLD>0)&&(AXLOC==XREAL)&&(AYLOC==YREAL)) {
  1906. X            if((nfound>=pager*5)&&(nfound<=4+(pager*5))) {
  1907. X                /*print that army to nfound%5*/
  1908. X                mvaddch((nfound%5)*2,COLS-21,'>');
  1909. X                if(selector==(nfound%5)*2) standout();
  1910. X                mvprintw((nfound%5)*2,COLS-20,"army %d: %d men  ",armynum,ASOLD);
  1911. X                mvprintw((nfound%5)*2+1,COLS-20," mv:%d st:%s",AMOVE,*(soldname+ASTAT));
  1912. X                standend();
  1913. X            }
  1914. X            nfound++;
  1915. X        }
  1916. X        if((occ[XREAL][YREAL]!=0)
  1917. X        &&(occ[XREAL][YREAL]!=country)
  1918. X        &&((SOWN==country)||((ASOLD>0)&&(AXLOC<=XREAL+1)
  1919. X        &&(AXLOC>=XREAL-1)&&(AYLOC<=YREAL+1)&&(AYLOC>=YREAL-1)))) 
  1920. X            found=1;
  1921. X    }
  1922. X
  1923. X    if(nfound<4+(pager*5)) for(nvynum=0;nvynum<MAXNAVY;nvynum++){
  1924. X        if(((NWAR+NMER)!=0)&&(NXLOC==XREAL)&&(NYLOC==YREAL)) {
  1925. X            if((nfound>=pager*5)&&(nfound<=4+(pager*5))) {
  1926. X                /*print a navy*/
  1927. X                mvaddch((nfound%5)*2,COLS-21,'>');
  1928. X                if(selector==(nfound%5)*2) standout();
  1929. X                mvprintw((nfound%5)*2,COLS-20,"navy %d: move %d",nvynum,NMOVE);
  1930. X                mvprintw((nfound%5)*2+1,COLS-20," war:%d mer:%d",NWAR,NMER);
  1931. X                standend();
  1932. X            }
  1933. X            nfound++;
  1934. X        }
  1935. X        if((occ[XREAL][YREAL]!=0)&&(occ[XREAL][YREAL]!=country)
  1936. X        &&(sct[XREAL][YREAL].altitude==WATER)
  1937. X        &&(NWAR+NMER>0)&&(NXLOC<=XREAL+1)&&(NXLOC>=XREAL-1)
  1938. X        &&(NYLOC<=YREAL+1)&&(NYLOC>=YREAL-1)) 
  1939. X            nvyfnd=1;
  1940. X    }
  1941. X
  1942. X    count=0;
  1943. X    if(found==1) for(i=0;i<NTOTAL;i++) {
  1944. X        if( !magic(i,HIDDEN) || country == 0 ){
  1945. X            enemy=0;
  1946. X            for(armynum=0;armynum<MAXARM;armynum++){
  1947. X                if((i!=country)
  1948. X                &&(ntn[i].arm[armynum].xloc==XREAL)
  1949. X                &&(ntn[i].arm[armynum].yloc==YREAL)
  1950. X                &&(ntn[i].arm[armynum].sold>0)) 
  1951. X                enemy+=ntn[i].arm[armynum].sold;
  1952. X            }
  1953. X            if(enemy>0) {
  1954. X                if((magic(country,SPY)==1) || country == 0 )
  1955. X                    mvprintw(nfound*2+count,COLS-20,"%s: %d men  ",ntn[i].name,enemy);
  1956. X                else if(magic(i,THE_VOID)==1){
  1957. X                mvprintw(nfound*2+count,COLS-20,"%s: ?? men  ",ntn[i].name);
  1958. X                clrtoeol();
  1959. X                }
  1960. X                else mvprintw(nfound*2+count,COLS-20,"%s: %d men  ",ntn[i].name,(enemy*(rand()%60+70)/100));
  1961. X                count++;
  1962. X            }
  1963. X        }
  1964. X    }
  1965. X    if(nvyfnd==1) for(i=0;i<NTOTAL;i++) {
  1966. X        if( magic(i,HIDDEN)!=1 || country == 0 ) 
  1967. X        for(nvynum=0;nvynum<MAXNAVY;nvynum++)
  1968. X        if((ntn[i].arm[nvynum].xloc==XREAL)
  1969. X        &&(ntn[i].arm[nvynum].yloc==YREAL)
  1970. X        &&(ntn[i].arm[nvynum].sold>0)){
  1971. X            if((magic(country,SPY)==1) || country == 0 ){
  1972. X                mvprintw(nfound*2+count,COLS-20,"%s: %d ships  ",
  1973. X                ntn[i].name,ntn[i].nvy[nvynum].warships+ntn[i].nvy[nvynum].merchant);
  1974. X            }
  1975. X            else if(magic(i,THE_VOID)==1){
  1976. X            mvprintw(nfound*2+count,COLS-20,"%s: ?? ships",ntn[i].name);
  1977. X            clrtoeol();
  1978. X            }
  1979. X            else mvprintw(nfound*2+count,COLS-20,"%s: %d ships  ",
  1980. X            ntn[i].name,(ntn[i].nvy[nvynum].warships+ntn[i].nvy[nvynum].merchant)*(rand()%6+7)/10);
  1981. X            count++;
  1982. X        }
  1983. X    }
  1984. X
  1985. X    standend();
  1986. X    mvprintw(11,COLS-20,"x is %d  ",XREAL);
  1987. X    mvprintw(11,COLS-11,"y is %d  ",YREAL);
  1988. X
  1989. X    if((country!=0)&&(sct[XREAL][YREAL].altitude==WATER)){
  1990. X        for(y=12;y<=20;y++) mvaddstr(y,COLS-20,"                    ");
  1991. X        mvaddstr(14,COLS-9,"WATER");
  1992. X    }
  1993. X    else {
  1994. X    if((country!=0)&&(country!=sct[XREAL][YREAL].owner)
  1995. X    &&(magic(sct[XREAL][YREAL].owner,THE_VOID)==1)){
  1996. X        for(y=13;y<=20;y++) mvaddstr(y,COLS-20,"                    ");
  1997. X    }
  1998. X    else {
  1999. X
  2000. X        for(y=13;y<=14;y++) mvaddstr(y,COLS-20,"                    ");
  2001. X
  2002. X        for(i=0;i<=7;i++)
  2003. X            if(sct[XREAL][YREAL].designation==*(des+i)){
  2004. X            mvprintw(13,COLS-20,"%s",*(desname+i));
  2005. X            clrtoeol();
  2006. X            }
  2007. X
  2008. X        if((sct[XREAL][YREAL].owner==country)||(country==0))
  2009. X        mvprintw(15,COLS-20,"people: %6d",sct[XREAL][YREAL].people);
  2010. X        else     
  2011. X        mvprintw(15,COLS-20,"people: %6d",sct[XREAL][YREAL].people*(rand()%60+70)/100);
  2012. X
  2013. X        if((sct[XREAL][YREAL].owner==country)
  2014. X        ||(sct[XREAL][YREAL].owner==0)
  2015. X        ||(sct[XREAL][YREAL].owner>=MAXNTN)){
  2016. X            mvprintw(17,COLS-20,"gold is:   %3d",sct[XREAL][YREAL].gold);
  2017. X            mvprintw(18,COLS-20,"iron is:   %3d",sct[XREAL][YREAL].iron);
  2018. X            if(sct[XREAL][YREAL].fortress>0){
  2019. X            if(sct[XREAL][YREAL].designation==DCASTLE)
  2020. X                armbonus=5*sct[XREAL][YREAL].fortress;
  2021. X            else if(sct[XREAL][YREAL].designation==DCITY){
  2022. X                if(magic(country,ARCHER)==1) armbonus=30;
  2023. X                if(magic(country,ARCHITECT)==1){
  2024. X                armbonus+=10+16*sct[XREAL][YREAL].fortress;
  2025. X                }
  2026. X                else armbonus+=10+8*sct[XREAL][YREAL].fortress;
  2027. X            }
  2028. X            else if(sct[XREAL][YREAL].designation==DCAPITOL){
  2029. X                if(magic(country,ARCHER)==1) armbonus=30;
  2030. X                if(magic(country,ARCHITECT)==1){
  2031. X                armbonus+=20+20*sct[XREAL][YREAL].fortress;
  2032. X                }
  2033. X                else armbonus+=20+10*sct[XREAL][YREAL].fortress;
  2034. X            }
  2035. X            mvprintw(19,COLS-20,"fortress: +%2d%%",armbonus);
  2036. X            }
  2037. X            else mvaddstr(19,COLS-20,"               ");
  2038. X        }
  2039. X        else {
  2040. X        for(y=17;y<=19;y++) mvaddstr(y,COLS-20,"                    ");
  2041. X        }
  2042. X    }
  2043. X
  2044. X    standout();
  2045. X    if(sct[XREAL][YREAL].owner==0) mvaddstr(12,COLS-20,"unowned");
  2046. X    else mvprintw(12,COLS-20,"owner: %s",ntn[sct[XREAL][YREAL].owner].name);
  2047. X    standend();
  2048. X    clrtoeol();
  2049. X
  2050. X    for(i=0;i<=10;i++)
  2051. X        if(sct[XREAL][YREAL].vegetation==*(veg+i))
  2052. X        mvprintw(13,COLS-9,"%s",*(vegname+i));
  2053. X
  2054. X    if(sct[XREAL][YREAL].owner!=0) for(i=1;i<=8;i++)
  2055. X        if(ntn[sct[XREAL][YREAL].owner].race==*(races+i)[0]){
  2056. X        mvprintw(14,COLS-20,"%s",*(races+i));
  2057. X        clrtoeol();
  2058. X        }
  2059. X
  2060. X    for(i=0;i<=4;i++)
  2061. X        if(sct[XREAL][YREAL].altitude==*(ele+i))
  2062. X        mvprintw(14,COLS-9,"%s",*(elename+i));
  2063. X    }
  2064. X
  2065. X    if(movecost[XREAL][YREAL]<0) 
  2066. X    mvaddstr(16,COLS-20,"YOU CAN'T ENTER HERE");
  2067. X    else
  2068. X    mvprintw(16,COLS-20,"move cost:  %2d      ",movecost[XREAL][YREAL]);
  2069. X
  2070. X}
  2071. END_OF_main.c
  2072. if test 20136 -ne `wc -c <main.c`; then
  2073.     echo shar: \"main.c\" unpacked with wrong size!
  2074. fi
  2075. # end of overwriting check
  2076. fi
  2077. if test -f run -a "${1}" != "-c" ; then 
  2078.   echo shar: Will not over-write existing file \"run\"
  2079. else
  2080. echo shar: Extracting \"run\" \(1789 characters\)
  2081. sed "s/^X//" >run <<'END_OF_run'
  2082. X#below is a shell script that runs updates 3 times a day every day but sunday
  2083. X#
  2084. X#PLEASE CHANGE TIME* VARIABLES TO APPROPRIATE TIMES, and CHANGE PATH VARIABLES
  2085. X#
  2086. X#KEEP THE TIMES IN CHRONOLOGICAL ORDER AND THE TIME1H and TIME2H values
  2087. X#represent the hours of TIME1 and TIME2
  2088. X#########################################################
  2089. X# use the command "at -l" to get a list of existing at jobs
  2090. X# use the command "at -r <jobname>" to remove existing at jobs
  2091. X#########################################################
  2092. XTIME1=1000
  2093. XTIME1H=10
  2094. XTIME2=1700
  2095. XTIME2H=17
  2096. XTIME3=2300
  2097. X#Below is the full command to update a game of conquer 
  2098. XPATHTOCONQ="/d7/c7913/smile/oldgame/conquer -x -d/d7/c7913/smile/oldgame/temp"
  2099. X#Path to this file
  2100. XPATHTORUN=/d7/c7913/smile/oldgame/run
  2101. X#LOG is full path name of log file
  2102. XLOG=/d7/c7913/smile/oldgame/runlog
  2103. X
  2104. X/bin/date >> $LOG
  2105. X$PATHTOCONQ >> $LOG
  2106. X
  2107. XDAY=`/bin/date | /usr/bin/awk '{ print $1 }'`
  2108. Xecho "day is $DAY" >> $LOG
  2109. XHOUR=`/bin/date|/usr/bin/awk '{ print $4 }'|/usr/bin/awk -F: '{ print $1 }'`
  2110. Xecho "hour is $HOUR" >> $LOG
  2111. X#BELOW IS AN EXAMPLE OF A BSD SCRIPT
  2112. X#switch $DAY
  2113. X#    case Sat:
  2114. X#        set nextday=mon
  2115. X#        breaksw
  2116. X#    default:
  2117. X#        set nextday =
  2118. X#        breaksw
  2119. X#endsw
  2120. Xcase $DAY in
  2121. X    Sat)
  2122. X         nextday=mon
  2123. X        ;;
  2124. X    *)
  2125. X         nextday=""
  2126. X        ;;
  2127. Xesac
  2128. X#switch $HOUR
  2129. X#    case 00:
  2130. X#        set nexthour=$TIME1
  2131. X#        breaksw
  2132. X#    default:
  2133. X#        set nexthour=$TIME2
  2134. X#        breaksw
  2135. X#endsw
  2136. Xcase $HOUR in
  2137. X$TIME1H)
  2138. X     nexthour=$TIME2
  2139. X    echo "nexthour is $nexthour" >> $LOG
  2140. X    ;;
  2141. X$TIME2H)
  2142. X     nexthour=$TIME3
  2143. X    echo "nexthour is $nexthour" >> $LOG
  2144. X    ;;
  2145. X*)
  2146. X    nexthour=$TIME1
  2147. X    echo "nexthour is $nexthour" >> $LOG
  2148. X    ;;
  2149. Xesac
  2150. X#below for bsd (i think)
  2151. X#/usr/bin/at $nexthour $nextday $PATHTORUN 
  2152. X#below for SYSV
  2153. Xecho "/usr/bin/at $nexthour $nextday < $PATHTORUN" >> $LOG
  2154. Xecho "XXX" >> $LOG
  2155. X/usr/bin/at $nexthour $nextday < $PATHTORUN 
  2156. END_OF_run
  2157. if test 1789 -ne `wc -c <run`; then
  2158.     echo shar: \"run\" unpacked with wrong size!
  2159. fi
  2160. # end of overwriting check
  2161. fi
  2162. echo shar: End of archive 3 \(of 6\).
  2163. cp /dev/null ark3isdone
  2164. MISSING=""
  2165. for I in 1 2 3 4 5 6 ; do
  2166.     if test ! -f ark${I}isdone ; then
  2167.     MISSING="${MISSING} ${I}"
  2168.     fi
  2169. done
  2170. if test "${MISSING}" = "" ; then
  2171.     echo You have unpacked all 6 archives.
  2172.     rm -f ark[1-9]isdone
  2173. else
  2174.     echo You still need to unpack the following archives:
  2175.     echo "        " ${MISSING}
  2176. fi
  2177. ##  End of shell archive.
  2178. exit 0
  2179.